<%@ page language="java" contentType="text/html; charset=utf8" import="com.wanda.model.Wd_UserModel"
    pageEncoding="utf8"%>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>授权</title> 


<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="<%=path1%>/qt/yjs/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="<%=path1%>/qt/yjs/bootstrap.min.js"></script>
    


<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/redmond/jquery-ui-1.8.2.custom.css"/>
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css"/>  
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>  
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap-theme.min.css">

<script type="text/javascript">


	function getElementsClass(classnames) {
		var classobj = new Array();//定义数组 
		var classint = 0;//定义数组的下标 
		var tags = document.getElementsByTagName("*");//获取HTML的所有标签 
		for ( var i in tags) {//对标签进行遍历 
			if (tags[i].nodeType == 1) {//判断节点类型 
				if (tags[i].getAttribute("class") == classnames)//判断和需要CLASS名字相同的，并组成一个数组 
				{
					classobj[classint] = tags[i];
					classint++;
				}
			}
		}
		return classobj;//返回组成的数组 
	}
	
	function uuse() {
		var roles = document.getElementsByName("role");
		var trs = getElementsClass("cbox cbox");
		for (var c = 0; c < roles.length; c++) {
			for (var x = 0; x < trs.length; x++) {
				//console.log("roles[c].id"+roles[c].id+"...."+trs[x].id)
				if (roles[c].id == trs[x].id) {
					console.log("1111111111111"+roles[c].checked)
					if (roles[c].checked) {
						trs[x].checked = "checked";
					}else{
						trs[x].checked = false;
					}
				}

			}
		}
	}
	
	
	
	
	
	
</script>
<script type="text/javascript">
$(document).ready(function(){
	 selectalluser();
})



function selectalluser(){
	$.ajax({ 	
	        type:"Post",  
	        dataType: 'json',  
	        url:"<%=path1%>/ht/selectAll.do", 
	        error:function(data){ 
	        //	alert(data);	 
	             alert("出错了！！");  
	        },  
	        success:function(data){
	        //	alert(data);
	        	//alert(data.rows[0].menu_name);
	        	
	        	 var sel= document.getElementById("use"); 
	             sel.options.add(new Option("请选择",""));
	        
	             jQuery.each(data.rows, function(i,item){ 
	           	  
	              sel.options.add(new Option(item.name,item.user_id));
	      		    
	             });
	        	
	         }  
	         }); 
}


function changeuserid(v){
	
	 changetestuser(v);
	 /*
	   $.ajax({ 	
	        data:{
	        	pid:"1"
	        },	
	        type:"Post",  
	        dataType: 'json',  
	        url:"<%=path1%>/function/selectAll", 
	        error:function(data){ 
	        //	alert(data);
	        abc = data;
	             alert("出错了！！");  
	        },  
	        success:function(data){
	        //	alert(data);
	        	//alert(data.rows[0].menu_name);
	        //	alert(data.rows.length);
	        	var str="";
	        	
	        	for(var c =0;c<data.rows.length;c++){
	        		str+="<input type='checkbox' id='jqg_list4_"+(c+1)+"' class='test' value='"+data.rows[c].id+"' name='role'/>"+data.rows[c].function_name;
	        		
	        	}
	        
	        	 $.ajax({ 	
	        	        data:{
	        	        	id:v.value
	        	        },	
	        	        type:"Post",  
	        	        dataType: 'json',  
	        	        url:"<%=path1%>/user_function/user_functionall", 
	        	        success:function(data){
	        	      
	        	        var test =  $(".test");
	        	        for (var i=0;i<test.length;i++)
	        	        {
	        	        	for(var c =0;c<data.rows.length;c++){
	        	        	
	                	        	if(test[i].value==data.rows[c].wd_function_id){
	                	        		test[i].checked="checked";
	                	        		//1111111
	                	        		
	                	        	}
	        	        	}
	        	     	        	
	        	        }
	        	       setTimeout(uuse(),1000);
	        	        	},
	        	        error:function(data){ 
	        	            //	alert(data);
	        	                 alert("出错了！！");  
	        	            }
	        	           
	        	   });  
	        	$("#haha").html(str);
	        	
	           }  
	         }
	   
	   ); 
	
	  */
	 
}
      var object =null;
       function changetestuser(v){
    	   if(object!=null){
    	   jQuery.each(object.rows, function(i,item){ 
       		 $("#list4").jqGrid('setSelection',item.wd_function_id);
	             }); 
    	   }
    	   
    	   
    	   $("#list4").jqGrid({
    	    	url:"<%=path1%>/function/selectAll",
    	        datatype:"json",  
    	        mtype:"POST",    
    	        height:320,  
    	        autowidth:true, 
    	       colNames:['id','权限名称'],
    	       colModel:[ 
    	{name:'id',index:'id',hidden:true},
    	{name:'function_name',index:'function_name', width:'90%',align:'center'},                  
    	
    	],
    	        multiselect:true,
    	        rownumbers:true,
    	        viewrecords: true,
    	        rowNum:100,
    	        rowList:[10,20,30,100],
    	        jsonReader:{ 
    	            id: "id",
    	            repeatitems : false
    	        },
    	        success: function (data) {  
    	        	alert(data);
    	        	
    	        },
    	        pager:$('#gridPager')
    	       
    	    });
    	   
    	
    	 //  postData:{'SearchSql':SearchSql}
    	   
    	   
    		 $.ajax({ 	
     	        data:{
     	        	id:v.value
     	        },	
     	        type:"Post",  
     	        dataType: 'json',  
     	        url:"<%=path1%>/user_function/user_functionall", 
     	        success:function(data){
     	        	object=data;
     	        	 jQuery.each(data.rows, function(i,item){ 
     	        		 $("#list4").jqGrid('setSelection',item.wd_function_id);
     		             }); 
     	        	},
     	        error:function(data){ 
     	                 alert("出错了！！");  
     	            }
     	           
     	   }); 
    	  
    	   
    	   
    	
    	  
    	
   
    	   
    	   
       }   
    	   /*
    	   
    	   $.ajax({ 	
   	        data:{
   	        	id:v.value
   	        },	
   	        type:"Post",  
   	        dataType: 'json',  
   	        url:"<%=path1%>/user_function/user_functionall", 
   	        success:function(data){
   	     
   	        var test =  $(".cbox cbox");  
   	        for (var i=0;i<test.length;i++)
   	        {
   	        	for(var c =0;c<data.rows.length;c++){
   	        	
           	        	if(test[i].value==data.rows[c].wd_function_id){
           	        		test[i].checked="checked";
           	        	}
   	        	}
   	        	 console.log(test[i].name)       	        	
   	        }
   	       
   	        	},
   	        error:function(data){ 
   	            //	alert(data);
   	                 alert("出错了！！");  
   	            }
    	   
    	   });
    	   */
    	   
     

       
       function getSelecteds(){  
    	 //获取多选到的id集合  
    	 var ids = $("#list4").jqGrid("getGridParam", "selarrrow");  
    	 //遍历访问这个集合  
    	 var use = $("#use").val();   
   
    	
    	/* 
    	  jQuery(ids).each(function(){

    	        alert(this.id);

    	    });
    	 */
         
    	 var mycars = new Array()
    	
    	 var i=0;
    	  ids.forEach(function(value, index, array) {
    		 var rowData = $("#list4").jqGrid("getRowData",value);	
        	 var rowName=rowData.id;
        	 mycars[i]=rowData.id;
        	 i++;
        	
    		});
    	   
    	
    	 
    	 
    	 window.location.href="../user_function/updateuser_function?ids="+mycars+"&use="+use;
    	
       /*
    	 $(ids).each(function (index, id){  
    		 
    	 //由id获得对应数据行  
    	 
    
    	 alert(ids);
    	 //var row = $("#list4").jqGrid('getRowData', id);  
    	// alert("row.ID:"+row.ID+"  "+"row.fieldName:"+row.fieldName);  
    	
    	 });
    	 */
   }     
       
       function ajaxSelect(){
    	   if($("#use").val()==""||$("#use").val()==''){
    		   alert("请选择用户");
    	   }else{
    		  
    		   var xxx=  $("#function_name").val();
      		    xxx="%"+xxx+"%";
    		 	$("#list4").jqGrid('setGridParam',{ 
    	              datatype:'json', 
    	              url:"<%=path1%>/function/selectbyfunction",
    	              postData:{'function1':xxx}, // 发送数据     //  where name like '%"+$("#name").val()+"%'
    	              page:1 
    	          }).trigger("reloadGrid");  
    		   
    		 	
    		 	
    		 	
    		 	
    		 	
    		 	
    		 	
    		 	
    		 	
    		 	
    		 
    		 /*	 var rowData = $("#list4").jqGrid("getRowData",6);	
            	 var rowName=rowData.id;
  		          alert(rowName);
  		         // var ids = jQuery("#list").jqGrid('getGridParam', 'selarrrow');
  		    var deal_status =$("#list").jqGrid("getRowData",rowid).Accept;
  		           if(rowid != undefined&&deal_status=="管理"){       
  		            jQuery("#list").jqGrid('setSelection', rowid);
  		            exportids +=rowid + ",";
  		        
  		       }      
  		        */
    		
    		   
    	   }
    	  
       }
       
       
</script>
    
  

</head>

<body>

 

    <div style="display: none">
   <div id="haha">  
   </div>
 </div>

 <table id="projectTable">
  
    <div class="yboxwidth boxcenter ybox01">
<div class="ybox09">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td style="padding-left: 20px"><table border="0" cellspacing="0" cellpadding="0">
          <tr valign="top" >
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >菜单信息列表</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
          </tr>
        </table></td>
        </tr>
    </table>
  </div>
  
  <div class="ybox02">
   <form action="../user_function/updateuser_function" method="post" style="margin:10px 400px; font-size:14px;">
   
      <span style="padding:0 50px"> 用户  <select id="use" name="use" onchange="changeuserid(this)" ></select></span>

   
   <input type="hidden"  style="display:inline-block;width:50px;
    height:25px;border-radius:4px;background-color:#b4d1e7; 
    text-align:center;line-height:20px;"/>
  </form> 
  
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
          <dl>
           
          </dl>
        </div>

                <div class="ybox05 margb8">
          <dl>
            <dt> <strong></strong>&nbsp;&nbsp;
                  权限名称：<input type="text" id="function_name"/> &nbsp;&nbsp;&nbsp;&nbsp;
	        
	       <img onclick="ajaxSelect()" src="images/bottonselect.gif" width="50" height="20" style="vertical-align: middle;cursor: pointer;" />
	           </dt>
          </dl>
        </div>
          
          <div class="ybox07 margb2">
          <dl><table border="0" cellspacing="0" cellpadding="0" class="ybox07table" >
              <tr align="left">
                <td class="ybox07td1"><img src="images/op4_6.gif" /></td>
                <td><span style="cursor:pointer;" onclick="getSelecteds()">修改用户权限</span></td>
          
                     
              </tr>
          </table>
          </dl>
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox06table" id="list4">        
          </table>
        
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
  </div>
</div>
  </table> 
   

</body>
</html>